package com.example.lineuppoject;

import android.app.Application;
import android.util.Log;

public class App extends Application {

    LineUpTaskHelp lineUpTaskHelp;

    @Override
    public void onCreate() {
        super.onCreate();
        lineUpTaskHelp = LineUpTaskHelp.getInstance();
        if (lineUpTaskHelp != null) {
            lineUpTaskHelp.setOnTaskListener(new LineUpTaskHelp.OnTaskListener() {
                @Override
                public void exNextTask(ConsumptionTask task) {

                    if (task instanceof RequestRunnable) {
                        Log.e("Post", "RequestRunnable");
                        RequestRunnable requestRunnable = (RequestRunnable) task;
                        requestRunnable.runnable.start();
                    } else if (task instanceof ConsumptionTask) {
                        Log.e("Post", "ConsumptionTask");
                    }
                }

                @Override
                public void noTask() {
                    Log.e("Post", "所有任务执行完成");
                }

                @Override
                public void timeOut(ConsumptionTask task) {
                    // 超时了.
                    Log.e("Post", "超时了,任务ID为：" + task.taskNo);
                    // 检查列队， 发现任务并开始执行
                    lineUpTaskHelp.exOk(task);
                }
            });
        }
    }
}
